package com.bdqn;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Iterator;

public class ShortAnswer4_view {
    public static void main(String[] args) {
        Document document = null;
        SAXReader saxReader = new SAXReader();
        try {
            document = saxReader.read("src/main/java/com/bdqn/Student.xml");
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        Element rootElement = document.getRootElement();
        for (Iterator iterator = rootElement.elementIterator();iterator.hasNext();){
            Element next =(Element) iterator.next();
            System.out.print("{学生id:" + next.attributeValue("id") + ",");

            Element name = next.element("name");
            Element course = next.element("course");
            Element score = next.element("score");

            System.out.println("学生姓名：" + name.getTextTrim() + "科目：" + course.getTextTrim() + "成绩：" + score.getTextTrim() + "}");

        }


    }
}
